<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <title>登陆</title>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="stylesheet" type="text/css" media="screen" href="/static/pc/css/reset.css"/>
    <link rel="stylesheet" type="text/css" media="screen" href="/static/pc/css/common.css"/>
    <link rel="stylesheet" type="text/css" media="screen" href="/static/pc/css/main.css" />
  </head>
  <body class="login-width-bg">
    <div class="login-wrapper">
        <div class="left">
            <img src="/static/pc/images/form_logo.png" style="width:299px;height:415px;"/>
        </div>
        <div class="right login-form">
            <p class='red login-title-word'>登录</p>
            <div class="login-form-item phone">
                <input type="text" placeholder="请输入手机号码" name="phone">
                <img src="/static/pc/images/close.png" width="17px" class="close" id="crlen"/>
            </div>
            <div class="login-form-item code ovh border-none">
                <div class="left" style="width:140px;border:2px solid #E5E5E5">
                    <input type="text" placeholder="请输入验证码" name="code">
                </div>
                <div class="right get-code-btn" id="get-code">
                    获取验证码
                </div>
            </div>
            <p class="regist-tip">
                还没有账号？<a class="red">注册</a>
            </p>
            <div class="login-form-item border-none" id="submit">
                <div class="form-btn">登录</div>
            </div>
            <div class="close-form">
                <img src="/static/pc/images/close1.png" width="25px" onclick="javascript:history.back(-1);"/>
            </div>
        </div>
    </div>
    <script type='text/javascript' src='/static/pc/js/jquery-3.3.1.min.js' charset='utf-8'></script>
    <script type='text/javascript' src='/static/wx/layui/layui.all.js' charset='utf-8'></script>
  </body>
  <script type='text/javascript'>
      $(function () {
          var countdown = 60;
          $('#crlen').on('click',function(){
              $("input[ name='phone']").val('');
          });
          function sendmsg() {
              if (countdown == 0) {
                  $("#get-code").css({"background-color": "red"});
                  $("#get-code").html("获取验证码");
                  countdown = 60;
                  return false;
              }
              else {
                  $("#get-code").css({"background-color": "#C0C0C0", "pointer-events": "none"});
                  $("#get-code").html(countdown + "s");
                  countdown--;
              }
              setTimeout(function () {
                  sendmsg();
              }, 1000);
          }
          //获取验证码
          $("#get-code").on('click',function () {
              var pattern = /^1[1345678]\d{9}$/;
              var phone = $("input[ name='phone']").val();
              if (pattern.test(phone) === false) {
                  layer.alert('请输入正确的手机号',{icon: 2})
                  return;
              }
              $.ajax({
                  type: 'POST',
                  url: "{:url('login/sendSms')}",
                  data: {
                      'phone': phone,
                      'type': 3
                  },
                  dataType: 'json',
                  success: function (Json) {
                      if (Json.code == 200) {
                          var takse = Json.data.code_id;
                          localStorage.setItem('takse',takse);
                          layer.alert('发送成功',{icon: 1})
                          sendmsg();
                      } else {
                          layer.alert(Json.msg,{icon: 2})
                      }
                  }
              });
          });
          //登录
          $("#submit").on('click',function () {
              var pattern = /^1[345678]\d{9}$/;
              var phone = $("input[ name='phone']").val();
              var code = $("input[ name='code']").val();
              pattern.test(phone);
              if (pattern.test(phone) === false) {
                  layer.alert('请输入正确的手机号',{icon: 2})
                  return;
              }
              if(code.length==0){
                  layer.alert('请输入验证码',{icon: 2})
                  return;
              }
              if(localStorage.getItem('takse') ==''){
                  layer.alert('您的验证码已失效',{icon: 2})
                  return;
              }
              $.ajax({
                  type: 'POST',
                  url: "{:url('login/login')}",
                  data: {
                      'phone': phone,
                      'code': code,
                      'tickets': localStorage.getItem('takse')
                  },
                  dataType: 'json',
                  success: function (Json) {
                      var data = Json.data;
                      if (Json.code == 200) {
                          if(data.role_id == 3){
                              location.href='/pc/insurant/check_data?menu_id=1';
                          }else if(data.role_id == 1){
                              location.href='/pc/insurer/step1';
                          }
                      } else {
                          layer.alert(Json.msg,{icon: 2})
                      }
                  }
              });
          });




      });



  </script>
</html>
